<?php

namespace DreamCat\ChanPool\Pojo;


use DreamCat\ChanPool\PoolEntryFactory;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;

/**
 * channel实现的共享池配置
 * @author vijay
 */
class ChannelPoolConfig
{
    /** @var int 尺寸 */
    private $size = 1;
    /** @var PoolEntryFactory 实体构建函数 */
    private $poolEntryFactory;
    /** @var float 超时时间 */
    private $timeSecond;
    /** @var LoggerInterface 日志记录器 */
    private $logger;

    /**
     * ChannelPoolConfig constructor.
     * @param PoolEntryFactory $poolEntryFactory 实体工厂
     */
    public function __construct(PoolEntryFactory $poolEntryFactory)
    {
        $this->poolEntryFactory = $poolEntryFactory;
    }

    /**
     * @return int 尺寸
     */
    public function getSize(): int
    {
        return $this->size;
    }

    /**
     * @param int $size 尺寸
     * @return static 对象本身
     */
    public function setSize(int $size): ChannelPoolConfig
    {
        if ($size > 0) {
            $this->size = $size;
        }
        return $this;
    }

    /**
     * @return PoolEntryFactory 实体构建函数
     */
    public function getPoolEntryFactory(): PoolEntryFactory
    {
        return $this->poolEntryFactory;
    }

    /**
     * @param PoolEntryFactory $poolEntryFactory 实体构建函数
     * @return static 对象本身
     */
    public function setPoolEntryFactory(PoolEntryFactory $poolEntryFactory): ChannelPoolConfig
    {
        $this->poolEntryFactory = $poolEntryFactory;
        return $this;
    }

    /**
     * @return float 超时时间
     */
    public function getTimeSecond(): ?float
    {
        return $this->timeSecond;
    }

    /**
     * @param float $timeSecond |null 超时时间
     * @return static 对象本身
     */
    public function setTimeSecond(float $timeSecond): ChannelPoolConfig
    {
        if ($timeSecond > 0) {
            $this->timeSecond = $timeSecond;
        }
        return $this;
    }

    /**
     * @return LoggerInterface 日志记录器
     */
    public function getLogger(): LoggerInterface
    {
        return $this->logger ?? new NullLogger();
    }

    /**
     * @param LoggerInterface $logger 日志记录器
     * @return static 对象本身
     */
    public function setLogger(LoggerInterface $logger): ChannelPoolConfig
    {
        $this->logger = $logger;
        return $this;
    }
}

# end of file
